package com.esun.common.utils;

import com.esun.common.enums.Message;
import com.esun.common.enums.UserMessage;
import org.apache.commons.lang.StringUtils;

/**
 * 消息多语言返回工具
 * @author John.xiao
 * @date 2021/8/10 17:49
 */
public class MessageUtils {
	private static final String DEFAULT_LANGUAGE = "CH";

	public String getMessage(String code) {
		return Message.getInfoByCode(code);
	}

	public String getMessage(String code, String language) {
		return Message.getInfoByCode(code);

	}

	public static String getCodeInfo(String code){
		return Message.getInfoByCode(code);
	}

	public static String getInfoByCode(String code) {
		if (StringUtils.isNotEmpty(code)) {
			Message[] messages = Message.values();
			for (Message message : messages) {
				if (message.getCode().equals(code)) {
					return message.getInfo();
				}
			}
			UserMessage[] userMessages = UserMessage.values();
			for (UserMessage userMessage : userMessages) {
				if (userMessage.getCode().equals(code)) {
					return userMessage.getInfo();
				}
			}
		}
		return null;
	}
}
